package com.yet.container.remote.netty.client;

import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;

import com.yet.container.registry.RegistryMeta.Address;
import com.yet.serialization.Serialization;

public class NettyClientPoolFactory extends BasePooledObjectFactory<NettyClient> {

	private Address address;
	private Serialization serialization;

	public NettyClientPoolFactory(Address address, Serialization serialization) {
		super();
		this.address = address;
		this.serialization = serialization;
	}

	@Override
	public NettyClient create() throws Exception {
		return new NettyClient(address, serialization);
	}

	@Override
	public PooledObject<NettyClient> wrap(NettyClient obj) {
		return new DefaultPooledObject<NettyClient>(obj);
	}

	@Override
	public void destroyObject(PooledObject<NettyClient> p) throws Exception {
		p.getObject().stop();
	}
}
